<template>
  <div class="app-container">
    <!-- 功能区 -->
    <transition name="formFade">
      <el-card class="operate-container" shadow="never" v-if="showSearch">
        <el-form :inline="true" :model="listQuery" @submit.native.prevent>
          <el-form-item label="工程名称" class="form-item">
            <el-input v-model="listQuery.projectName" clearable class="filter-item" placeholder="工程名称"/>
          </el-form-item>
          <el-form-item label="工程规模:" class="form-item">
            <el-select placeholder="请选择" style="width:100%;" clearable v-model="listQuery.scale"
                       class="form-select" :popper-append-to-body="false" popper-class="select-popper">
              <el-option v-for="item in scaleList" :value="item.code" :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="工程状态:" class="form-item">
            <el-select placeholder="请选择" style="width:100%;" clearable v-model="listQuery.status"
                       class="form-select" :popper-append-to-body="false" popper-class="select-popper">
              <el-option v-for="item in statusList" :value="item.code" :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="form-item">
            <el-button size="mini" icon="el-icon-refresh" @click="colse">重置</el-button>
            <el-button type="primary" size="mini" icon="el-icon-search" @click="getList">查询</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </transition>
    <div class="table_content">
      <headerSearch :showAdd="false"
                    @creRefresh="getList"
                    @isSearch="showSearch = !showSearch"></headerSearch>
      <!--表格渲染-->
      <el-table ref="table" v-loading="loading" :data="list" style="width: 100%;" border
                :header-cell-style="{background: '#F8F8F9',padding: '6px 0 !important',color: '#515a6e'}">
        <af-table-column prop="projectName" fixed="left" label="工程名称" />
        <af-table-column prop="scale" label="工程规模" />
        <af-table-column prop="orgName" label="机构名称" />
        <af-table-column prop="needBidding" label="是否需要招标" >
          <template slot-scope="scope">
            {{{'0':'不需要招标','1':'需要招标'}[scope.row.needBidding]}}
          </template>
        </af-table-column>
        <af-table-column prop="status" label="工程状态">
          <template slot-scope="scope">
            {{scope.row.status | statusFilter}}
          </template>
        </af-table-column>
        <af-table-column prop="estabTime" label="立项提交时间" />
        <af-table-column prop="biddingType" label="招标方式" />
        <af-table-column prop="biddingTime" label="招标提交时间" />
        <af-table-column prop="constructMan" label="施工单位负责人" />
        <af-table-column prop="constructUnit" label="施工单位" />
        <af-table-column prop="commenceDate" label="开工日期" />
        <af-table-column prop="rectifyStop" label="是否整改暂停" >
          <template slot-scope="scope">
            {{{'0':'正常','1':'整改暂停'}[scope.row.rectifyStop]}}
          </template>
        </af-table-column>
        <af-table-column align="center" fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button class="btn" type="text" size="small"
                       @click="seeEdit(scope.$index,scope.row)">查看</el-button>
          </template>
        </af-table-column>
      </el-table>

      <!--分页-->
      <pagination v-show="total>0" :total="total"
                  :page.sync="listQuery.pageNum"
                  :limit.sync="listQuery.pageSize"
                  @pagination="getList" />
    </div>
  </div>
</template>

<script>
  import { doPost, doGet, doFile, orglistChild } from '@/api/index'
  import Pagination from '@/components/Pagination/index'
  import {statusList, scaleList} from '@/utils/validate'
  import headerSearch from '@/components/headerSearch/headerSearch'

  export default {
    name: "projectList",
    components: {Pagination, headerSearch},
    data() {
      return {
        loading: false,
        showSearch: true,
        list: [
          {
            id: 0,
            projectName: '测试工程项目名称',
            orgName: '测试机构名称',
            scale: 20,
            investment: 10000,
            needBidding: 0,
            status: '00',
            estabTime: '2022-06-29 12:33:33'
          }
        ],
        total: 0,
        listQuery: {
          pageNum: 1,
          pageSize: 20,
          projectName: '',
          scale:'',
          status: ''
        },
        statusList,
        scaleList,
      }
    },
    created() {
      // this.getList()
    },
    methods: {
      colse() {
        this.listQuery = {
          pageNum: 1,
          pageSize: 20,
          projectName: '',
          scale:'',
          status: ''
        }
      },
      getList() {
        this.loading = true
        doPost('project/page',this.listQuery).then(res => {
          this.loading = false
          this.list = res.data.list
          this.total = res.data.total
        }).catch(error => {
          this.list = []
          this.total = 0
          this.loading = false
        })
      },
      //查看详情
      seeEdit(index, row) {
        this.$router.push({ name: 'productDetail', params: { id: row.id }})
      },
    },
    filters: {
      statusFilter(val) {
        return {
          '00':'立项',
          '01':'立项待审批',
          '02':'立项审批通过',
          '40':'开始招标',
          '41':'招标待审批',
          '42':'招标审批通过',
          '60':'项目建设开工',
          '61':'开工待审批',
          '62':'开工审批通过/建设',
          '80':'工程验收',
          '81':'验收待审批',
          '82':'验收审批通过',
          '99':'项目归档',
        }[val]
      }
    }
  }
</script>

<style scoped>

</style>
